package com.example.singletontest;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zbc
 * @description
 * @email
 * @date 2020/12/24 20:24
 */
public class ContainerSingleton {
    private ContainerSingleton() { }

    private static final Map<String, Object> ioc = new ConcurrentHashMap<>();

    public static Object getBean(String className){
        if (!ioc.containsKey(className)){
            Object obj = null;
            try {
                obj = Class.forName(className).newInstance();
                ioc.put(className, obj);
            }catch (Exception e){
                e.printStackTrace();
            }
            return obj;
        }
        return ioc.get(className);
    }
}
